<?php

/**
 * This is the model class for table "detalles_ot".
 *
 * The followings are the available columns in table 'detalles_ot':
 * @property integer $id
 * @property integer $id_detalle_reparacion
 * @property integer $id_ot
 * @property integer $cantidad
 * @property integer $id_marca
 * @property string $observacion
 * @property integer $precio_unitario
 *
 * The followings are the available model relations:
 * @property DetalleReparacion $idDetalleReparacion
 * @property OrdenTrabajo $idOt
 * @property MarcasRepuestos $idMarca
 */
class DetallesOt extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return DetallesOt the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'detalles_ot';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_detalle_reparacion, id_ot, id_marca, observacion, precio_unitario', 'required'),
			array('id_detalle_reparacion, id_ot, cantidad, id_marca, precio_unitario', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, id_detalle_reparacion, id_ot, cantidad, id_marca, observacion, precio_unitario', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idDetalleReparacion' => array(self::BELONGS_TO, 'DetalleReparacion', 'id_detalle_reparacion'),
			'idOt' => array(self::BELONGS_TO, 'OrdenTrabajo', 'id_ot'),
			'idMarca' => array(self::BELONGS_TO, 'MarcasRepuestos', 'id_marca'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_detalle_reparacion' => 'Id Detalle Reparacion',
			'id_ot' => 'Id Ot',
			'cantidad' => 'Cantidad',
			'id_marca' => 'Id Marca',
			'observacion' => 'Observacion',
			'precio_unitario' => 'Precio Unitario',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('id_detalle_reparacion',$this->id_detalle_reparacion);
		$criteria->compare('id_ot',$this->id_ot);
		$criteria->compare('cantidad',$this->cantidad);
		$criteria->compare('id_marca',$this->id_marca);
		$criteria->compare('observacion',$this->observacion,true);
		$criteria->compare('precio_unitario',$this->precio_unitario);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}